//
//  DataModel.m
//  groupProject
//
//  Created by mac on 15/12/28.
//  Copyright © 2015年 mac. All rights reserved.
//

#import "DataModel.h"
#import "Config.h"
#import "UIImageView+WebCache.h"
@implementation DataModel



- (void) decodeResponseObject:(NSDictionary *)object {
    NSLog(@"开始解析数据");
    
    _dataArray = object[@"result"];

    //ser上获取的 //同步获取的get方式  数据量大得时候 需要 使用多线程编程或者异步下载方式，避免阻塞；
    NSURL *url = [self getURLByName:@"imageScroll.plist"];
    NSArray * tmpArray = [NSArray arrayWithContentsOfURL:url];
    //转化成模型 存入数组
    _SCImgeViewArray = [NSMutableArray array];
    for (NSDictionary *dic in tmpArray) {
        //第二次请求获取图片
        UIImageView *tmpimageview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCROLL_HEIGHT)];
        [tmpimageview sd_setImageWithURL:[self getURLByName:dic[@"imageName"]] placeholderImage:[UIImage imageNamed:@"user_head.png"]];
        [_SCImgeViewArray addObject:tmpimageview];
        NSLog(@"获取图片。。。。。");
    }
}

-(NSURL *)getURLByName:(NSString *)name {
    NSString *urlstring;
    for (NSDictionary *dic in _dataArray) {
        if ([dic[@"name"] isEqualToString:name]) {
            urlstring = dic[@"url"];
            break;
        }
    }
    //有中文 进行处理
    urlstring = [urlstring stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    return [NSURL URLWithString:urlstring];
}

- (NSMutableArray *) getImageArrayByplist:(NSString *)listName {
    NSMutableArray *imageArray = [NSMutableArray new];
    NSURL *url = [self getURLByName:listName];
    NSArray * tmpArray = [NSArray arrayWithContentsOfURL:url];
    //转化成模型 存入数组
    _SCImgeViewArray = [NSMutableArray array];
    for (NSDictionary *dic in tmpArray) {
        //第二次请求获取图片
        UIImageView *tmpimageview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCROLL_HEIGHT)];
        [tmpimageview sd_setImageWithURL:[self getURLByName:dic[@"imageName"]] placeholderImage:[UIImage imageNamed:@"user_head.png"]];
        [imageArray addObject:tmpimageview];
        NSLog(@"获取图片。。。。。%@", listName);
    }
    return imageArray;

}


@end
